package com.xcdh.commons.utils;

import com.sun.istack.internal.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ListUtil
 *
 * @author wjg
 * @date 2024/4/9
 */
public class ListUtil {

    @SafeVarargs
    public static <T> List<T> asList(T ...ele) {
        return Arrays.stream(ele).collect(Collectors.toList());
    }

    public static <T> List<List<T>> lisGroup(int limit ,@NotNull List<T> data){
        int size = data.size();
        limit = Math.min(Math.max(limit , 1) , size) ;
        int page = 1 ,startIndex = 0;
        List<List<T>> result = new ArrayList<>() ;
        do{
            List<T> ts = data.subList(startIndex, Math.min(page * limit , size));
            result.add(ts) ;
            startIndex = (++page -1) *  limit ;
        }while(startIndex < size) ;
        return result ;
    }

}
